package com.ihome.excel.xlsx.engine.export;

import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;

import com.ihome.excel.xlsx.entity.ExcelRule;
import com.ihome.excel.xlsx.exceptions.ThrowableDefine;

public class SheetWriteEngine {

	public Sheet createSheet(Workbook wb,ExcelRule excelRule) {
		if(wb == null) {
			throw ThrowableDefine.PARAMETER_VALIDATE_EXP.getIllegaArgumentExp("wb");
		}
		if(excelRule == null) {
			throw ThrowableDefine.PARAMETER_VALIDATE_EXP.getIllegaArgumentExp("excelRule");
		}
		Sheet sheet = wb.createSheet(excelRule.getSheetName());
		sheetStyle(sheet, excelRule);
		return sheet;
	}
	
	private void sheetStyle(Sheet sheet,ExcelRule excelRule) {
		int columnHeadLength = excelRule.getColumnHeadNameConfig().size();
		/**
		 * 设置单元格宽度
		 */
		for(int i = 0 ; i < columnHeadLength ; i ++) {
			sheet.setColumnWidth(i, excelRule.getColumnHeadNameConfig().get(i).getWidth() * 30);
		}
	}
	
}
